<script>
var submitElem;
$(document).ready(function(){
	submitElem = $("#ModuleName").closest('form').find('input:submit');
	$("#ModuleName").change(function(){
		submitElem.attr('disabled',true);
		 $.get(URL+"/admin/modules/getParams/"+$("#ModuleName").val(), function(data){
			 submitElem.attr('disabled',false);
				$("#params").html(data);
			});
	});
});
</script>
<?php
$tabs->addTab(__("General"), $form->inputs(array('fieldset'=>false), null, 'general'));

$content = null;

if(count(ClassRegistry::getObject('Module')->getFields('group','params')) ==  0)
{
	$content = __("No parameter present.");
}
else
{
	$content = $form->inputs(array('fieldset'=>false), null, 'params');
}
$tabs->addTab(__("Parameters"), $content, array('tab_id' => 'params'));
$visibiltyCheckValue = "all";
if(isset($this->data['ModuleVisibility']) && count($this->data['ModuleVisibility']) > 0)
{
	$visibiltyCheckValue = "selected";
}
$triggers = $form->input("visibilty_check",array("type"=>"radio",'options'=>array("all"=>__("All pages"),"selected"=>__("Selected Pages")),'value'=>$visibiltyCheckValue,'class'=>"visibilty_check"));
//if all value is selected.
$visibilityTab = $form->input('show_on_pages',array("type"=>"hidden")); 
$visibilityTab .= $triggers . '<div id="page_selector" class="hidden">' .
$form->inputs(array('fieldset'=>false), null, 'visibility') . "</div>";
$tabs->addTab(__("Visibility"), $visibilityTab);

$advancedTab = $form->inputs(array('fieldset'=>false), null, 'advanced');
$tabs->addTab(__("Advanced"), $advancedTab);
echo $tabs->show(array('container_id'=>"module_form"));

// js to hide filter and filter_value fields in 'visibility' tab
$actions = cri('Cms.Sitemap')->getActions('level', 0);
$dynamicActions = array();
foreach($actions as $action)
{
	$action = GigaActionHandler::get($action);
	if($action->isDynamic())
	{
		$dynamicActions[] = $action->id;
	}
	//pr($dynamicActions);
}
$dynamicActionsJson = json_encode($dynamicActions);

echo $javascript->link('/cms/js/php.js');
?>
<script>
window.dynamicActions = <?php echo $dynamicActionsJson; ?>;
$(document).ready(function(){
	$("[name$='[action_id]']").live('beforeFetchingOptions', function(){
		if(!in_array($(this).val(), window.dynamicActions))
		{
			$(this).data('disableFetching', true);
		}
		else
		{
			$(this).parent().siblings('div').eq(0).removeClass('hidden');
		}
	});

	$("[name$='[filter]']").live('beforeFetchingOptions', function(){
		$(this).parent().siblings('div').eq(1).removeClass('hidden');
	});

	$('select.action').each(function(){
		if(in_array($(this).val(), window.dynamicActions))
		{
			$(this).parent().siblings('div').removeClass('hidden');
		}		
	});


	$('input.visibilty_check').change(function()
	{
		updateVisibilityOptions();		
	});
	if("<?php echo $isVisibilityFilterEnabled?>" == true)
	{
		$('input[name=visibility_radio]').eq(1).attr('checked',true);
	}
	updateVisibilityOptions();
});

function updateVisibilityOptions()
{
	if($('input[value=selected]').attr('checked'))
	{
		$('#page_selector').show('slow');
		$('#page_selector input, #page_selector select').attr('disabled', false);
	}
	else
	{
		$('#page_selector').hide('slow');
		$('#page_selector input, #page_selector select').attr('disabled', true);
	}
}
</script>